package game;

import game.ui.FullScreenGamePanel;

import javax.swing.*;
import java.awt.*;

public class Game extends JFrame {
	private static int DESIRED_FPS = 80;
	private static final long MILLISECONDS_TO_NANOSECONDS = 1000000L;
	private static final long PERIOD_IN_MS = (long) 1000.0 / DESIRED_FPS;
	private static final String WINDOW_TITLE = "Game";

	public static void main(String args[]) {
		printInitialStatistics();
		new Game(PERIOD_IN_MS * MILLISECONDS_TO_NANOSECONDS);
	}

	private static void printInitialStatistics() {
		System.out.println("fps: " + DESIRED_FPS + "; period: " + PERIOD_IN_MS + " ms");
	}

	public Game(long periodInNanos) {
		super(WINDOW_TITLE);
		configureMainWindowElements(periodInNanos);
		turnOffBordersAndTitleBar();
		turnOffAutomaticPaintEvents();
		beginRendering();
	}

	private void beginRendering() {
		pack();
		setResizable(false);
		setVisible(true);
	}

	private void configureMainWindowElements(long periodInNanos) {
		final Container c = getContentPane();
		c.setLayout(new BorderLayout());
		final FullScreenGamePanel panel = new FullScreenGamePanel(this, periodInNanos);
		c.add(panel, "Center");
	}

	private void turnOffAutomaticPaintEvents() {
		setIgnoreRepaint(true);
	}

	private void turnOffBordersAndTitleBar() {
		setUndecorated(true);
	}
}